﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using T.FAS.Runtime.Base.Dao;
using T.FAS.Runtime.ScheduleJob.SPI;
using T.ServiceComponent.DAC.Service;
using T.ServiceComponent.DataAccessEx.Core;

namespace T.FAS.Runtime.ScheduleJob.Dao
{
    public class SysExecuteFrequencyDao : DaoService<SysExecuteFrequency>
    {
        public override string TableName => "FAS_SysExecuteFrequency";
        public override string IDColumnName => "ID";

        public override List<string> ExceptColumnName
            => DaoUtil.GetExceptionColumn<SysExecuteFrequencyDao>(
                new List<string>
                {
                    "FrequencyContentDic",
                    "DayValue",
                    "HourValue"
                }
            );
        public SysExecuteFrequencyDao() : base()
        {
            DBName = "TFAS";
        }
        public override SysExecuteFrequency ConvertToObject(Dictionary<string, PropertyInfo> columns, DataRow row)
        {
            return base.ConvertToObject(columns, row);
        }
        public override Dictionary<string, object> GetDataMapping(SysExecuteFrequency data)
        {
            return base.GetDataMapping(data);
        }
        public override Dictionary<string, PropertyInfo> GetColumns()
        {
            return base.GetColumns();
        }

        public SysExecuteFrequency GetExecuteFrequencyByID(string id)
        {
            //var data = base.Get(id);
            //return data as SysExecuteFrequency;
            var dt = base.GetByFilter($" {IDColumnName} = '{id}'");
            var metadatas = DaoUtil.ConvertToEntity<SysExecuteFrequency>(dt, this.ExceptColumnName);
            InternationalDaoTools.FillInternationalFields(metadatas, dt, this);
            return metadatas?.FirstOrDefault();
        }
        public List<SysExecuteFrequency> GetSysExecuteFrequencies()
        {
            //var result = base.GetObjectsByFilter($" IsEnable = 1");
            //var list = new List<SysExecuteFrequency>();
            //if (result != null && result.Count > 0)
            //{
            //    result.ForEach(r => list.Add(r as SysExecuteFrequency));
            //}
            //return list.OrderBy(x => x.SortOrder).ToList();
            var dt = base.GetByFilter($" IsEnable = 1");
            var metadatas = DaoUtil.ConvertToEntity<SysExecuteFrequency>(dt, this.ExceptColumnName);
            InternationalDaoTools.FillInternationalFields(metadatas, dt, this);
            return metadatas;
        }
    }
}
